<?php

namespace LhpAmis\Traits;
use LhpAmis\Renderers\Amis;

/**
 * 事件处理Trait类
 */
trait EventTrait
{
    protected function onEvent(string $eventName, $actions = [])
    {
        if (is_string($actions)) {
            $actions = $this->$actions();
        }
        return [
            $eventName => [
                'actions' => $actions,
            ],
        ];
    }
    protected function custom(string $script)
    {
        return [
            'actionType' => 'custom',
            'script' => $script,
        ];
    }
    protected function reload()
    {
        return [
            'actionType' => 'custom',
            'script' => 'window.location.reload()',
        ];
    }
}
